package org.doubango.FrCall.Screens;

import org.doubango.FrCall.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

public class NumberRegisterCheck extends Activity {
	private Button nToFinish;
	private Button numRegBackToNumInput;
	private TextView tvNum;//显示号码
	private EditText etNum;//验证码
	String num;
	String number;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.register_number_check);
		nToFinish = (Button) findViewById(R.id.n_to_finish);
		numRegBackToNumInput = (Button) findViewById(R.id.num_reg_back_input_num);
		tvNum=(TextView) findViewById(R.id.show_number);
		etNum=(EditText) findViewById(R.id.checknumber);
		Intent i=getIntent();
		number=i.getStringExtra("number");
		tvNum.setText("手机号："+number);
		nToFinish.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				if(validate()){
					num=etNum.getText().toString();
					String s=number.substring(number.length()-4,number.length());
					if(num.equals(s)){
						Intent intent = new Intent(NumberRegisterCheck.this,NumberRegisterOk.class);
						startActivity(intent);
						finish();
					}else{
						Toast.makeText(getApplicationContext(),"验证码不匹配，应为手机后4位，请重新输入",Toast.LENGTH_LONG).show();
					}
				}
			}
		});
		
		numRegBackToNumInput.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				
				Intent intent = new Intent(NumberRegisterCheck.this,NumberRegister.class);
				startActivity(intent);
				finish();
				}
		});
		
	}
	 private boolean validate(){
	    	num=etNum.getText().toString();
	 		if(num.equals("")){
                Toast.makeText(getApplicationContext(),"验证码不能为空",Toast.LENGTH_LONG).show();
	 			return false;
	 		}
	    	return true;
	    }
}
